package binary_tree.leetcode;

/**
 * 判断是否是镜像的树
 * @Author Stark
 * @Date 2022/2/21 17:37
 */
public class Num101_SymmetricTree {
    public boolean isSymmetric(TreeNode root) {
        if(root == null){
            return true;
        }
        return judgeIsSymmetric(root.left,root.right);
    }

    public boolean judgeIsSymmetric(TreeNode left, TreeNode right) {
        //如果走到两边的子树都为空,说明该分支相同
        if(left == null && right == null){
            return true;
        }
        //如果只要满足一种情况就不相同
        if(left == null || right == null){
            return false;
        }
        //值不想等也返回假
        if(left.val != right.val){
            return false;
        }
        return judgeIsSymmetric(left.left,right.right) && judgeIsSymmetric(left.right,right.left);
    }
}
